package com.yueke.gemini.utils;

import java.io.*;
import java.util.Properties;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;

/**
 * Created by admin on 2017/10/21.
 */
public class PropertiesUtil {

    //自定义ResourceBundle读取的文件路径
    private static ResourceBundle rb;
    private static BufferedInputStream inputStream;
    static {
        String proFilePath = System.getProperty("user.dir") +"\\config\\resourceBundle.properties";
        try {
            inputStream = new BufferedInputStream(new FileInputStream(proFilePath));
            rb = new PropertyResourceBundle(inputStream);
            inputStream.close();
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    public static Properties loadProps(String fileName) {
        Properties props = null;
        InputStream is = null;

        try {
            is = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName);
            if (is == null) {
                throw new ClassNotFoundException(fileName + " file is not found");
            }
            props = new Properties();
            props.load(is);
        } catch (ClassNotFoundException | IOException e) {
            e.printStackTrace();
        } finally {
            if (is != null){
                try {
                    is.close();
                }catch (IOException e){
                    System.out.println("close input stream failure"+ e);
                }
            }
        }
        return props;
    }
}
